Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
new Function("JS string") unavoidable?

On an API call from online stores to our Rails app, I need to send strings of HTML, CSS and JS to build a modal on their frontend. If the HTML and CSS are not an issue, the JS looks problematic as I am willing to use new Function ("js script in string") to add JS to my modal.

I read everywhere that new Function(), like eval(), is not secure at all but I cannot see any other way to do it.

To give more context, I am subject to two constraints

  • I have hundreds of templates saved in my DB (template_id, html, css, js) that can be called by each store
  • I need to access functions/modules that have been declared before like in the example below
import moduleX from 'moduleX'

const functionX = () => { something() }

const runJS = (js_string) => {
  const specificJS = new Function('moduleX', 'functionX', js_string)
  specificJS(moduleX, functionX)
}

const buildPopup = (popup_data) => {
  insertHtml(popup_data.html)
  insertCss(popup_data.css)
  runJS(popup_data.js)
}

Is there a more secure way to do it?

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda